package com.zhihuichongcheng.application.ui.task.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.base.BaseActivity;
import com.zhihuichongcheng.application.bean.mine.UserBean;
import com.zhihuichongcheng.application.net.HttpManager;
import com.zhihuichongcheng.application.ui.BaseApplication;

/**
 * base holder Created by LK on 2017/1/9.
 */
public abstract class BaseHolder extends RecyclerView.ViewHolder {
    protected HttpManager manager;
    protected UserBean mUser;
    protected BaseApplication app;
    protected BaseActivity activity;

    public BaseHolder(View itemView, BaseActivity activity) {
        super(itemView);
        this.activity = activity;
        app = (BaseApplication) activity.getApplication();
        mUser = app.getUser();
        manager = HttpManager.getInstance(itemView.getContext());
    }

    protected void startActivity(Class cls) {
        startActivity(cls, null);
    }

    protected void startActivity(Class cls, Bundle bundle) {
        Context mContext = itemView.getContext();
        Intent intent = new Intent(mContext, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        mContext.startActivity(intent);
        if (mContext instanceof FragmentActivity) {
            ((FragmentActivity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        }
    }

    protected void startActivityForResult(Class cls, int RequestCode, Bundle bundle) {
        Context mContext = itemView.getContext();
        Intent intent = new Intent(mContext, cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        if (mContext instanceof FragmentActivity) {
            ((FragmentActivity) mContext).startActivityForResult(intent, RequestCode);
            ((FragmentActivity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        }
    }

    public Context getContext() {
        return itemView.getContext();
    }

}
